
/**
 * 延期项目，是以实际开始日期PLBegDate+PDay生成新的计划完工日期
 * @param {Object} data
 */
export function dateFormat(data){
	data.forEach((item, key) => {
		data[key]['PBegDate'] = item.PBegDate ? timestampToTime(new Date(item.PBegDate).getTime() / 1000) : "--";
		data[key]['PLBegDate'] = item.PLBegDate ? timestampToTime(new Date(item.PLBegDate).getTime() / 1000) : "--"
		data[key]['PLEndDate'] = item.PLEndDate ? timestampToTime(new Date(item.PLEndDate).getTime() / 1000) : "--";
		data[key]['PFinishDate'] = item.PFinishDate ? timestampToTime(new Date(item.PFinishDate).getTime() / 1000) : "--";
		data[key]['PCreatRyDate'] = item.PCreatRyDate ? timestampToTime(new Date(item.PCreatRyDate).getTime() / 1000) : "--";
		if(parseInt(item.PState) == 4) {
			let second  = new Date(item.PBegDate).getTime() / 1000 + parseInt(item.PDay) * 60 * 60 *24;
			data[key]['PEndDate'] = timestampToTime(second);		
		}else {
			data[key]['PEndDate'] = timestampToTime(new Date(item.PEndDate).getTime()  / 1000);		
		}
	})
	return data;
}
/**
 * 时间戳转日期[年-月-日 时:分:秒]
 */
export function timestampToTime(timestamp) {
  var date = new Date(timestamp * 1000);
  var Y = date.getFullYear() + "-";
  var M =
    (date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1) + "-";
  var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
  var h = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
  var m = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) + ":";
  var s = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  return Y + M + D + h + m + s;
}
/**
 * 时间戳转日期[年-月-日]
 */
export function timestampToDate(timestamp) {
  var date = new Date(timestamp * 1000);
  var Y = date.getFullYear() + "-";
  var M =
    (date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1) + "-";
  var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());
  return Y + M + D;
}

/**
 * 今天日期日期
 */
export function today() {
  var date = new Date();
  var Y = date.getFullYear() + "-";
  var M =
    (date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1) + "-";
  var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());
  return Y + M + D ;
}